package org.familysearch.fsapi.gwt.server.test;

import java.util.ArrayList;

import org.apache.log4j.Logger;
import org.familysearch.fsapi.gwt.common.client.entities.Temple;
import org.familysearch.fsapi.gwt.server.api.APIException;
import org.familysearch.fsapi.gwt.server.api.TempleAPI;

import junit.framework.TestCase;

public class TempleTestCase extends TestCase {

	private TempleAPI api = new TempleAPI();
	private Logger log;
	
	public TempleTestCase()
	{
		log = Logger.getLogger(this.getClass().getName());
	}

    public void test_templeToString()
    {
    	Temple temple = new Temple();
    	assertEquals(temple.toString(), "[temple[code=null][name=null][location=null][dedication-date=null]]");
    }

	
    public void test_getTempleByCode()
    {
    	
    	Temple t1 = new Temple();
    	t1.setCode("TORON");
    	
    	Temple f1 = null;
    	try {
			f1 = api.getTemple(t1);
		} catch (APIException e) {
			log.error(e.toString());
		}
		
		assertNotNull(f1);
		log.debug(f1);
    	
    }
	
    public void test_getTwoTemplesSameSession()
    {
    	
    	Temple t1 = new Temple();
    	t1.setCode("TORON");    	
    	Temple f1 = null;
    	
    	Temple t2 = new Temple();
    	t2.setCode("ACCRA");    	
    	Temple f2 = null;
    	
    	
    	try {
			f1 = api.getTemple(t1);
			f2 = api.getTemple(t2);
		} catch (APIException e) {
			log.error(e.toString());
		}
		
		assertNotNull(f1);
		log.debug(f1);

		assertNotNull(f2);
		log.debug(f2);
    }    
    
    
    public void test_getTemples()
    {
    	
    	ArrayList temples = null;
    	try {
			temples = api.getTemples();
		} catch (APIException e) {
			log.error(e.toString());
		}
		
		// should be 133 (as of 21 June 2008)
		assertEquals(temples.size(), 133);
		log.debug(temples);

    }      

	
    
}
